<?php
session_start();
include("config.php");
if ($_SESSION['admin']!="OK")
{
	echo "<script language='javascript'>alert('Please log in!');window.location.href='login.php';</script>";
	exit;
}

if ($_POST['actions']=="1")
{
	$addtitle=addslashes(trim($_POST['titles'])); 
	$addchoise=trim($_POST['choice']); 
	if ($addchoise=="1")
		$ch="a";
	else
		$ch="b";
	$conn=mysql_connect($host,$user,$password); 
	mysql_query("SET NAMES UTF8");
	mysql_select_db($db); 
	$sql="insert into vote_title (title,options) values('$addtitle','$ch')";
	$result=mysql_query($sql);
	$titleid=mysql_insert_id();
	mysql_close();
	/* echo "<script language='javascript'>alert('Topic Added Succeed!');</script>"; */
	if($result) header("location:addchoice.php?id=$titleid");
}
?>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Questionnaire Survey System Management</title> 
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function check_message(){
	if(window.document.addtitle.titles.value==""){
		alert("The Topic can not be empty!");
		document.addtitle.titles.focus();
		return false;}
		return true;
}
</script>
</head> 
<body>
<div id=main>
<div class=title>Add Vote Topic</div>
<div id="menu">
<ul>
		<li><a href='admin.php'>Administraction</a></li>
		<li><a href="editadmin.php">Your Account</a></li>
		<li><a href="addtitle.php" class="top">Add vote topic</a></li>
		<li><a href="showvote.php" target="_blank">Vote result</a></li>
		<li><a href="javascript:$msg=confirm('Are u sure to clean the result?');$msg?window.location.href='clearResult.php':history.go(0);">Delete Result</a></li>
		<li><a href="loginout.php">Log out</a></li>
		<li><a href="index.php" target="_blank">Home</a></li>
</ul>
</div>
<form action="" method="post" name="addtitle" id="addtitle">
<div class=main1>
<div class="user2">Vote Topic: <input type="text" name="titles" id="titles" size="100">no larger than 200</div>
</div>
<div class=main1>
<div class="user3">Set 'Single' or 'Multiple'<input name="choice" type="radio" value="1" checked>Single<input type="radio" name="choice" value="2">Multiple</div>
</div>
<div class=main1>
<div class="submit3"><input name="submit" type="submit" value="submit" onClick="return check_message()" class="inputs"/>
<input name="B2" type="reset" value="reset" class="inputs" />
<input name="actions" type="hidden" id="actions" value="1"/>
</div>
</div>
</form>
</div>
<br />
<center>CopyRight@FengYL</center>
</body>
</html>
